﻿/// <reference path="D:\Documents\Visual Studio 2013\Projects\WinnerCMS\WinnerCMS.WebUI\Scripts/knockout-3.3.0.debug.js" />

function GetUserLogin() {
    
    $.ajax({
        type: "GET",
        url: "/api/User/ShowUserLogin",
        contentType: 'application/json',
        beforeSend: function () {
            $("#btnLogin").text("处理中...");
        },
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            alert(xmlHttpRequest.statusText);

        },
        success: function (info) {
            ko.cleanNode($("#div_MemberBar .left")[0]);
            ko.applyBindings(info, $("#div_MemberBar .left")[0]);
        }
    });
}


function UserLogout() {
    $.ajax({
        type: "post",
        url: "/api/User/Logout",
        success: function (info) {
            window.location = window.location; //注销成功以后刷新网页。
        }
    });
}

function PostLogin() {
    var data = {
        UserName: $("#UserName").val(),
        PassWord: $("#PassWord").val(),
        PassCode: $("#PassCode").val()
    };
    if (data.UserName == "") {
        alert("请输入用户名");
        return;
    }
    if (data.PassWord == "") {
        alert("请输入密码");
        return;
    }
   
    $.ajax({
        type: 'POST',
        url: "/api/User/Login",
        contentType : "application/json",
        dataType: 'json',
        data: JSON.stringify(data) ,
        beforeSend: function () {
            $("#UserLoginUI input[type=\"button\"]").val("处理中...");
        },
        error: function (msg) {
            alert("post 登录出错。");
        },
        success: function (result) {
            if (result.errors !== "") {
                alert(result.errors);
            }
            GetUserLogin();
        }
    });
}

$(function () {
    
    GetUserLogin();
});